/*
 * @lc app=leetcode.cn id=264 lang=java
 *
 * [264] 丑数 II
 */

// @lc code=start
class Solution {
    public int nthUglyNumber(int n) {
        int[] chou = new int[n];
        Arrays.fill(chou,1);//初始化为1
        int[] idx = new int[3];
        for(int i = 1;i<n;i++){
            int a = chou[idx[0]*2] , b = chou[idx[1]*3] , c = chou[idx[2]*5];
            int next = Math.min(a,Math.min(b,c));
            if(next==a){
                idx[0]++;
            }
            if(next==b){
                idx[1]++;
            }
            if(next==c){
                idx[2]++;
            }
            chou[i]=next;

        }
        return chou[n-1];
    }
}
// @lc code=end

